package com.opengate.base.exception;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @author 曳戈泰尔
 * @version 1.0
 * @description 异常枚举
 * @date 2023/4/26 5:46 PM
 */
@Getter
@AllArgsConstructor
@Schema(description = "异常枚举")
public enum ExceptionCodeEnum {
    sys_0001(-1, "业务繁忙，请稍后重试", "Server is busy, please try again later"),
    sys_0002(-2, "限流操作", "Server is busy, please try again later"),
    sys_0003(-3, "参数有误", "Incorrect parameter");

    @Schema(description = "状态码", required = true)
    private final int code;

    @Schema(description = "描述", required = true)
    private final String desc;

    @Schema(description = "英文描述", required = true)
    private final String descEn;

    /**
     * 根据状态码获取枚举
     *
     * @param errorCode 状态码
     * @return 枚举
     */
    public static ExceptionCodeEnum getEnumByErrorCode(int errorCode) {
        for (ExceptionCodeEnum errorEnum : ExceptionCodeEnum.values()) {
            if (errorEnum.code == errorCode) {
                return errorEnum;
            }
        }
        return null;
    }
}
